package cc.rengu.igas.bsps.core.service.trans;


import cc.rengu.igas.bsps.common.dao.*;
import cc.rengu.igas.bsps.common.dao.impl.*;
import cc.rengu.igas.bsps.common.entity.MchntBaseInfo;
import cc.rengu.igas.bsps.common.entity.MchntBindInfo;
import cc.rengu.igas.bsps.common.entity.PlatformMchntInfo;
import cc.rengu.igas.bsps.common.entity.UserInfo;
import cc.rengu.igas.bsps.common.enums.RespCodeEnum;
import cc.rengu.igas.bsps.common.enums.RoleTypeEnum;
import cc.rengu.igas.bsps.core.service.base.ManageService;
import cc.rengu.igas.bsps.facade.bean.TransDetailInfoBean;
import cc.rengu.igas.bsps.facade.bean.TransSumInfoBean;
import cc.rengu.igas.bsps.facade.request.TransDetailQueryRequest;
import cc.rengu.igas.bsps.facade.response.TransDetailQueryResponse;
import cc.rengu.igas.share.common.util.SensitiveDataUtil;
import cc.rengu.igas.share.core.model.GroupMchntInfo;
import cc.rengu.igas.share.core.realize.MchntService;
import cc.rengu.igas.share.core.realize.impl.MchntServiceImpl;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.dao.UserOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.MchntOrderInfo;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.TxnCfg;
import cc.rengu.oltp.service.common.entity.UserOrderInfo;
import cc.rengu.oltp.service.common.enums.PayTypeEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.realize.BinInfoService;
import cc.rengu.oltp.service.realize.impl.BinInfoServiceImpl;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.BeanUtil;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.DateUtil;
import cc.rengu.oltp.utility.util.StringUtil;
import com.alibaba.fastjson.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 交易明细列表查询
 * Created by yuhongwen
 */
public class TransDetailQueryService extends ManageService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        TransDetailQueryRequest tradeDetailListQueryRequest = new TransDetailQueryRequest();
        ConvertUtil.convertOutput(tradeDetailListQueryRequest);
        return tradeDetailListQueryRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        TransDetailQueryRequest tradeDetailListQueryRequest = (TransDetailQueryRequest) request;
        TransDetailQueryResponse tradeDetailListQueryResponse = new TransDetailQueryResponse();
        BeanUtil.beanCopy(tradeDetailListQueryRequest, tradeDetailListQueryResponse);

        String instId = tradeDetailListQueryRequest.getHeader().getInstId();
        String mchntType = tradeDetailListQueryRequest.getQueryType();
        String userId = tradeDetailListQueryRequest.getUserId();
        String mchntNo = tradeDetailListQueryRequest.getMchntNo();
        String cashierId = tradeDetailListQueryRequest.getCashierId();
        String startDate = tradeDetailListQueryRequest.getStartDate();
        String endDate = tradeDetailListQueryRequest.getEndDate();
        String payType = tradeDetailListQueryRequest.getPayType();
        String devRiskInfo = tradeDetailListQueryRequest.getDevRiskInfo();
        String minAmt = tradeDetailListQueryRequest.getMinAmt();
        String maxAmt = tradeDetailListQueryRequest.getMaxAmt();
        String mchntOrderId = tradeDetailListQueryRequest.getMchntOrderId();
        String transType = tradeDetailListQueryRequest.getTxnNum();
        String queryId = tradeDetailListQueryRequest.getQueryId();

        /* 参数合法性校验 */
        rglog.info("必填性校验");
        if (StringUtil.isEmptyOrNull(mchntNo) || StringUtil.isEmptyOrNull(startDate) || StringUtil.isEmptyOrNull(endDate)) {
            rglog.error("商户号<{}>,开始日期<{}>,截止日期<{}>不能为空!", mchntNo, startDate, endDate);
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        rglog.info("校验查询日期范围");
        if (DateUtil.compareDate(startDate, endDate) > 0 || DateUtil.compareDate(DateUtil.getBaseDateOffsetMonth(startDate, 1), endDate) < 0) {
            rglog.info("查询时间超范围");
            throw new BizException(RespCodeEnum.DATESPAN_CHECK_ERROR.getRespCode(), RespCodeEnum.DATESPAN_CHECK_ERROR.getRespDesc());
        }

        /* 普通商户 获取当前用户身份(是否设置查询订单权限) */
        if (StringUtil.isEmptyOrNull(mchntType) || "00".equals(mchntType)) {
            //00-普通商户
            //查询当前用户身份
            BspsMchntBindInfoMapper bspsMchntBindInfoMapper = new BspsMchntBindInfoMapperImpl();
            MchntBindInfo mchntBindInfo = bspsMchntBindInfoMapper.selectBspsMchntBindInfoListByUserIdAndMchntNo(instId, userId, mchntNo);
            if (mchntBindInfo == null) {
                rglog.error("用户绑定商户信息查询失败！");
                throw new BizException(RespCodeEnum.USER_MCHNT_BIND_INFO_ERROR.getRespCode(), RespCodeEnum.USER_MCHNT_BIND_INFO_ERROR.getRespDesc());
            } else {
                //角色为02-收银员时,判断是否设置查询订单权限
                if (RoleTypeEnum.CASHIER.getRoleType().equals(mchntBindInfo.getBindUserRole())) {
                    String remark1 = mchntBindInfo.getRemark1();
                    if (StringUtil.isEmptyOrNull(remark1)) {
                        //若未设置订单查询权限,则只查询该收银员(用户)下的交易订单明细
                        cashierId = userId;
                    } else {
                        JSONObject jsonObject = JSONObject.parseObject(remark1);
                        String transInfoQueryAuth = jsonObject.getString("adminAuth");
                        //判断该收银员是否拥有查询全部订单的权限
                        cashierId = AppParamConstant.YES.equals(transInfoQueryAuth) ? "" : userId;
                    }
                }
            }
        }

        /* 查询商户信息 */
        BspsMchntBaseInfoMapper mchntBaseInfoMapper = new BspsMchntBaseInfoMapperImpl();
        if ("20".equals(mchntType)) {
            //20-平台商户
            /* 查询平台商户 */
            BspsPlatformMchntInfoMapper platMchntInfoMapper = new BspsPlatformMchntInfoMapperImpl();
            PlatformMchntInfo platformMchntInfo = platMchntInfoMapper.selectBspsPlatformMchntInfoByInstIdAndMchntNo(instId, mchntNo);
            if (platformMchntInfo == null) {
                rglog.info("获取商户信息失败！");
                throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
            }
            tradeDetailListQueryResponse.setMchntNo(platformMchntInfo.getPlatMchntNo());
            tradeDetailListQueryResponse.setMchntName(platformMchntInfo.getPlatMchntName());
        } else if ("10".equals(mchntType)) {
            //10-集团商户
            MchntService mchntService = new MchntServiceImpl();
            GroupMchntInfo groupMchntInfo = mchntService.getGroupMchntInfo(instId, mchntNo);
            if (groupMchntInfo == null) {
                rglog.info("获取商户信息失败！");
                throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
            }
            tradeDetailListQueryResponse.setMchntNo(groupMchntInfo.getGroupMchntNo());
            tradeDetailListQueryResponse.setMchntName(groupMchntInfo.getGroupMchntName());
        } else {
            MchntBaseInfo mchntBaseInfo = mchntBaseInfoMapper.selectBspsMchntBaseInfoByPrimaryKey(instId, mchntNo);
            if (mchntBaseInfo == null) {
                rglog.info("获取商户信息失败！");
                throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
            }

            if ("10".equals(mchntBaseInfo.getMchntType())) {
                //连锁商户
                mchntType = "30";
            } else {
                //普通商户或门店
                mchntType = "00";
            }
            tradeDetailListQueryResponse.setMchntNo(mchntBaseInfo.getMchntNo());
            tradeDetailListQueryResponse.setMchntName(mchntBaseInfo.getMchntName());
            tradeDetailListQueryResponse.setMchntType(mchntBaseInfo.getMchntType());
        }

        /* 查询 集团商户信息列表 */
        List<MchntOrderInfo> mchntOrderInfolist = null;
        List<MchntOrderInfo> mchntOrderInfolistRun = null;
        //查询汇总
        TradeDetailInfoMapper tradeDetailInfoMapper = new TradeDetailInfoMapperImpl();
        if ("P01".equals(transType) || StringUtil.isEmptyOrNull(transType)) {
            mchntOrderInfolist = tradeDetailInfoMapper.selectMchntOrderGroupByDate(instId, mchntNo, startDate, endDate, cashierId, "P01", payType, null, minAmt, maxAmt, mchntOrderId, mchntType, queryId);
        }
        if ("P04".equals(transType) || StringUtil.isEmptyOrNull(transType)) {
            mchntOrderInfolistRun = tradeDetailInfoMapper.selectMchntOrderGroupByDate(instId, mchntNo, startDate, endDate, cashierId, "P04", payType, null, minAmt, maxAmt, mchntOrderId, mchntType, queryId);
        }

        /* 时间段 */
        List<String> dateslist = findDates(startDate, endDate);
        List<TransSumInfoBean> transSumInfoList = new ArrayList<>();
        for (int i = 0; i < dateslist.size(); i++) {
            TransSumInfoBean transSumInfoBean = new TransSumInfoBean();
            String date = dateslist.get(i);
            String transAmt = "0";
            String transNum = "0";
            String transAmtRun = "0";
            String transNumRun = "0";
            if ((mchntOrderInfolist == null || mchntOrderInfolist.size() == 0) && (mchntOrderInfolistRun == null || mchntOrderInfolistRun.size() == 0)) {
                transSumInfoBean.setTxnDate(date);
                transSumInfoBean.setTransNum("0");
                transSumInfoBean.setTransAmt("0");
                transSumInfoList.add(transSumInfoBean);
                rglog.info(date + "数据为0条!");
            } else {
                if (mchntOrderInfolist != null && mchntOrderInfolist.size() != 0) {
                    //查看当天是否有正向交易数据
                    List<MchntOrderInfo> mchntOrderList = mchntOrderInfolist.stream().filter(item -> date.equals(item.getTxnDate())).collect(Collectors.toList());
                    boolean mchntOrderListIsnull = (mchntOrderList == null || mchntOrderList.size() == 0);
                    transAmt = mchntOrderListIsnull ? "0" : mchntOrderList.get(0).getRemark1();
                    transNum = mchntOrderListIsnull ? "0" : mchntOrderList.get(0).getRemark2();
                }
                if (mchntOrderInfolistRun != null && mchntOrderInfolistRun.size() != 0) {
                    //查看当天是否有退款交易
                    List<MchntOrderInfo> mchntOrderListRun = mchntOrderInfolistRun.stream().filter(item -> date.equals(item.getTxnDate())).collect(Collectors.toList());
                    boolean mchntOrderListRunIsnull = (mchntOrderListRun == null || mchntOrderListRun.size() == 0);
                    transAmtRun = mchntOrderListRunIsnull ? "0" : mchntOrderListRun.get(0).getRemark1();
                    transNumRun = mchntOrderListRunIsnull ? "0" : mchntOrderListRun.get(0).getRemark2();
                }

                /* 计算出当天的总数量与总交易值 */
                BigDecimal transAmtDecimal = new BigDecimal(transAmt);
                BigDecimal transAmtDecimalb = new BigDecimal(transAmtRun);
                String dateTransAmt = transAmtDecimal.subtract(transAmtDecimalb).toString();

                BigDecimal transNumDecimal = new BigDecimal(transNum);
                BigDecimal transNumRunDecimalb = new BigDecimal(transNumRun);
                String dateTransNum = transNumDecimal.add(transNumRunDecimalb).toString();

                transSumInfoBean.setTxnDate(date);
                transSumInfoBean.setTransNum(dateTransNum);
                transSumInfoBean.setTransAmt(dateTransAmt);
                transSumInfoList.add(transSumInfoBean);
            }
        }
        tradeDetailListQueryResponse.setTransSumInfoList(transSumInfoList);

        /* 查询交易明细信息 */
        rglog.info("分页信息赋值");
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageIndex(tradeDetailListQueryRequest.getPageIndex());
        pageInfo.setPageSize(tradeDetailListQueryRequest.getPageSize());
        String state = null;
        PageResult pageResult = tradeDetailInfoMapper.selectPayOrderPage(instId, mchntNo, startDate, endDate, cashierId, pageInfo, payType, minAmt, maxAmt, mchntOrderId, transType, state, mchntType, queryId);

        if (pageResult == null || pageResult.getResult().isEmpty()) {
            rglog.info("根据查询条件,数据为0条!");
            tradeDetailListQueryResponse.setTotalPage(0);
            tradeDetailListQueryResponse.setTotalRows(0);
        } else {
            List<TransDetailInfoBean> transDetailInfos = new ArrayList<>();
            for (Object object : pageResult.getResult()) {
                MchntOrderInfo mchntOrderInfo = (MchntOrderInfo) object;
                rglog.info("mchntOrderInfo订单详情信息：" + JSONObject.toJSONString(mchntOrderInfo));
                convTransDetailInfo(mchntOrderInfo, transDetailInfos, instId);
            }
            tradeDetailListQueryResponse.setTransDetailInfoList(transDetailInfos);
            tradeDetailListQueryResponse.setTotalPage(pageResult.getPageInfo().getTotalPage());
            tradeDetailListQueryResponse.setTotalRows(pageResult.getPageInfo().getTotalRows());
        }
        /* 按照接口转换基础产品信息并响应给请求方 */
        BizResponse bizResponse = new BizResponse();
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(tradeDetailListQueryResponse);
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        TransDetailQueryResponse tradeDetailListQueryResponse = (TransDetailQueryResponse) bizResponse.getResult();
        ConvertUtil.convertInput(tradeDetailListQueryResponse);
    }


    /**
     * 交易明细信息转换
     *
     * @param mchntOrderInfo   商户订单信息
     * @param transDetailInfos 接口返回交易明细信息
     * @param instId           机构号
     */
    private void convTransDetailInfo(MchntOrderInfo mchntOrderInfo, List<TransDetailInfoBean> transDetailInfos, String instId) {
        TransDetailInfoBean transDetailInfoBean = new TransDetailInfoBean();
        transDetailInfoBean.setTxnNum(mchntOrderInfo.getTxnNum());
        transDetailInfoBean.setTxnDate(mchntOrderInfo.getTxnDate());
        transDetailInfoBean.setTxnTime(mchntOrderInfo.getTxnTime());
        transDetailInfoBean.setBizStatus(mchntOrderInfo.getBizStatus());
        transDetailInfoBean.setTransStatus(mchntOrderInfo.getTransStatus());
        transDetailInfoBean.setMchntOrderId(mchntOrderInfo.getMchntOrderId());
        transDetailInfoBean.setSysSeqNum(mchntOrderInfo.getSysSeqNum());
        transDetailInfoBean.setTransAmt(mchntOrderInfo.getOrderAmt());
        transDetailInfoBean.setRefundAmt(mchntOrderInfo.getRefundAmt());
        transDetailInfoBean.setRealMchntFee(mchntOrderInfo.getRealMchntFee());
        transDetailInfoBean.setBizSceneType(mchntOrderInfo.getBizSceneType());

        try {
            /* 查询本交易的商户信息 */
            BspsMchntBaseInfoMapper mchntBaseInfoMapper = new BspsMchntBaseInfoMapperImpl();
            MchntBaseInfo mchntBaseInfo = mchntBaseInfoMapper.selectBspsMchntBaseInfoByPrimaryKey(mchntOrderInfo.getInstId(), mchntOrderInfo.getMchntNo());
            if (mchntBaseInfo != null) {
                transDetailInfoBean.setMchntNo(mchntBaseInfo.getMchntNo());
                transDetailInfoBean.setMchntName(mchntBaseInfo.getMchntName());
                transDetailInfoBean.setMchntType(mchntBaseInfo.getMchntType());
            }

            /* 查询支付订单表信息 */
            TradeDetailInfoMapper tradeDetailInfoMapper = new TradeDetailInfoMapperImpl();
            List<PayOrderInfo> payOrderInfoList = tradeDetailInfoMapper.bspsSelectPayOrderInfoBySysSeqNum(instId, mchntOrderInfo.getSysSeqNum());
            if (payOrderInfoList != null) {
                payOrderInfoList = payOrderInfoList.stream().filter(item -> ((!"0007".equals(item.getChannelBizType()) && !"0014".equals(item.getChannelBizType())))).collect(Collectors.toList());
                if (payOrderInfoList.size() != 0) {
                    PayOrderInfo payOrderInfo = payOrderInfoList.get(0);
                    //支付类型
                    String orderPayType = payOrderInfo.getPayType();
                    transDetailInfoBean.setPayType(orderPayType);
                    //支付方信息
                    String payerAcctInfo = payOrderInfo.getPayerAcctInfo();
                    transDetailInfoBean.setPayerAcctInfo(payerAcctInfo);
                    //付款方账户类型
                    payOrderInfo.setPayerAcctType(payOrderInfo.getPayerAcctType());
                    //(支付表)实际支付金额 real_pay_amt
                    transDetailInfoBean.setTransAmt(payOrderInfo.getRealPayAmt());
                    //(支付表)付款方类型 payer_acct_type
                    transDetailInfoBean.setPayerAcctType(payOrderInfo.getPayerAcctType());

                    if (!StringUtil.isEmptyOrNull(payerAcctInfo)) {
                        if ("00".equals(orderPayType) || "01".equals(orderPayType) || "04".equals(orderPayType)) {
                            //支付方式为银行卡的进行掩码
                            if (!StringUtil.isEmptyOrNull(payerAcctInfo)) {
                                //银行账号,脱敏规则:前6后4,中间全部用*代替
                                String payAcctNo = SensitiveDataUtil.desensitization("2", payerAcctInfo);
                                transDetailInfoBean.setPayerAcctInfo(payAcctNo.split("\\|")[0]);
                                rglog.debug("查询对应的付款账号<{}>", transDetailInfoBean.getPayerAcctInfo());
                            }
                            //获取发卡行名称
                            String issInstCode = payOrderInfo.getIssInstCode();
                            BinInfoService binInfoService = new BinInfoServiceImpl();
                            transDetailInfoBean.setIssuerName(binInfoService.getIssNameFromBinInfo(issInstCode));
                        }
                    }
                }
            }

            /* 查询交易码表->获取交易名称 */
            List<TxnCfg> txnCfgList = tradeDetailInfoMapper.selectTxnCfgByBizType(mchntOrderInfo.getTxnNum(), mchntOrderInfo.getBizType());
            if (txnCfgList != null) {
                transDetailInfoBean.setTxnName(txnCfgList.get(0).getTxnName());
                if (StringUtil.isEmptyOrNull(transDetailInfoBean.getPayType())){
                    if (transDetailInfoBean.getTxnName().contains("微信")){
                        transDetailInfoBean.setPayType(PayTypeEnum.WECHAT.getPayType());
                    }else if (transDetailInfoBean.getTxnName().contains("支付宝")){
                        transDetailInfoBean.setPayType(PayTypeEnum.ALIPAY.getPayType());
                    }else if (transDetailInfoBean.getTxnName().contains("云闪付")){
                        transDetailInfoBean.setPayType(PayTypeEnum.CUPS_CLOUD.getPayType());
                    }else {
                        transDetailInfoBean.setPayType(PayTypeEnum.OTHER.getPayType());
                    }
                }
            }

            /* 查询用户表->获取收银员标识、收银员昵称 */
            UserInfoMapper userInfoMapper = new UserInfoMapperImpl();
            UserInfo userInfo = userInfoMapper.selectBspUserInfoByPrimaryKey(mchntOrderInfo.getInstId(), mchntOrderInfo.getUserId());
            if (userInfo != null) {
                transDetailInfoBean.setCashierId(userInfo.getUserId());
                transDetailInfoBean.setUserName(userInfo.getNickName());
            }

            /* 查询用户订单表->获取订单备注 */
            UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
            UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByPrimaryKey(mchntOrderInfo.getInstId(), mchntOrderInfo.getSysSeqNum());
            if (userOrderInfo != null) {
                transDetailInfoBean.setOrderDesc(userOrderInfo.getOrderDesc());
            }

            /* 交易为退款时(支付信息取原交易的) */
            if ("04".equals(mchntOrderInfo.getTxnNum().substring(1, 3))) {
                rglog.debug("查询退款对应的原支付交易<{}>,对应的退款流水<{}>", mchntOrderInfo.getSysSeqNum(), mchntOrderInfo.getOrigSysSeqNum());
                List<PayOrderInfo> payOrderInfoLists = tradeDetailInfoMapper.bspsSelectPayOrderInfoBySysSeqNum(instId, mchntOrderInfo.getOrigSysSeqNum());
                if (null != payOrderInfoLists) {
                    String origPayType = payOrderInfoLists.get(0).getPayType();
                    if ("00".equals(origPayType) || "01".equals(origPayType) || "04".equals(origPayType)) {
                        if (!StringUtil.isEmptyOrNull(payOrderInfoLists.get(0).getPayerAcctInfo())) {
                            //银行账号,脱敏规则:前6后4,中间全部用*代替
                            String payAcctNo = SensitiveDataUtil.desensitization("2", payOrderInfoLists.get(0).getPayerAcctInfo());
                            rglog.debug("5查询对应的付款账号<{}>", payAcctNo);
                            transDetailInfoBean.setPayerAcctInfo(payAcctNo.split("\\|")[0]);
                        }
                    } else {
                        transDetailInfoBean.setPayerAcctInfo(payOrderInfoLists.get(0).getPayerAcctInfo());
                        rglog.debug("6查询对应的付款账号<{}>", payOrderInfoLists.get(0).getPayerAcctInfo());
                    }
                    rglog.debug("7查询对应的付款账号<{}>", transDetailInfoBean.getPayerAcctInfo());
                }
            }

            if (StringUtil.isEmptyOrNull(transDetailInfoBean.getPayerAcctInfo())) {
                transDetailInfoBean.setPayerAcctInfo("--");
            }
        } catch (Exception e) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(byteArrayOutputStream, true));
            rglog.error("获取交易明细信息失败:{}", byteArrayOutputStream.toString());
        }
        transDetailInfos.add(transDetailInfoBean);
    }


    public List<String> findDates(String stime, String etime) throws Exception {
        List<String> allDate = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        Date dBegin = sdf.parse(stime);
        Date dEnd = sdf.parse(etime);
        allDate.add(sdf.format(dBegin));
        Calendar calBegin = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        // 使用给定的 Date 设置此 Calendar 的时间
        calEnd.setTime(dEnd);
        // 测试此日期是否在指定日期之后
        while (dEnd.after(calBegin.getTime())) {
            // 根据日历的规则，为给定的日历字段添加或减去指定的时间量
            calBegin.add(Calendar.DAY_OF_MONTH, 1);
            allDate.add(sdf.format(calBegin.getTime()));
            Thread.sleep(100);
        }
        return allDate;
    }
}

